package com.my.interview.proxy.jdk_proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class JDKProxy implements InvocationHandler {


    private Object target;

    public Object getTarget() {
        return target;
    }


    public void setTarget(Object target) {
        this.target = target;
    }

    public Object getProxy(){

        return Proxy.newProxyInstance(this.getClass().getClassLoader(), this.target.getClass().getInterfaces(), this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

        System.out.println(method.getName());
        System.out.println("=======JDKProxy===========");
        return method.invoke(target, args);
    }
}
